<template>
  <div class="container">
    <el-dialog title="修改付款账户" :visible.sync="eduitestablishDialog.eduitDialogVisible" width="30%" center
      :lock-scroll="true" @open="getData" @close="hideDialog">
      <el-form ref="form" :model="formData" label-width="100px" label-position="left">
        <el-form-item label="付款账户：" v-if="select">
          <el-select v-model="formData.describe" placeholder="请选择付款账户">
            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="confirm()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
  import {
    selectBankAccountList,
    caiwuStatementbank,
  } from "@/api/settlement/settlementList";
  import { FailChangeBank } from "@/api/settlement/bankList";

  import {
    smkselectBankAccountList,
    smkcaiwuStatementbank,
  } from "@/api/superSettlement/settlementList";
  import { smkFailChangeBank } from "@/api/superSettlement/bankList";
  export default {
    props: {
      eduitestablishDialog: Object,
    },
    data() {
      return {
        formData: {
          describe: "",
        },
        options: [],
        select: true,
      };
    },
    methods: {
      getData() {
        this.options = [];
        if (
          this.eduitestablishDialog.dialogType == "send" ||
          this.eduitestablishDialog.dialogType == "falssend"
        ) {
          selectBankAccountList().then((res) => {
            if (res.code == 0) {
              res.data.data.forEach((data) => {
                this.options.push({
                  value: data.id,
                  label: `${data.bank_name}[${data.account}](${data.area_name})`,
                });
              });
            }
          });
        } else {
          smkselectBankAccountList().then((res) => {
            if (res.code == 0) {
              res.data.data.forEach((data) => {
                this.options.push({
                  value: data.id,
                  label: `${data.bank_name}[${data.account}](${data.area_name})`,
                });
              });
            }
          });
        }
        this.formData.describe = this.eduitestablishDialog.paymentname;
      },
      hideDialog() {
        this.eduitestablishDialog.eduitDialogVisible = false;
        this.formData.describe = "";
      },
      //提交
      confirm() {
        console.log(this.eduitestablishDialog.dialogType, 3232432);
        let data = {
          pay_id: this.eduitestablishDialog.id,
          payment_id: this.formData.describe == "" ? "" : this.formData.describe,
        };
        if (this.eduitestablishDialog.dialogType == "send") {
          caiwuStatementbank(data).then((res) => {
            if (res.code == 0) {
              this.$message({
                type: "success",
                message: res.msg || res.message,
              });
              this.hideDialog();
              this.$emit("upData");
            } else {
              this.$message({
                type: "error",
                message: res.msg || res.message,
              });
            }
          });
        } else if (this.eduitestablishDialog.dialogType == "falssend") {
          FailChangeBank(data).then((res) => {
            if (res.code == 0) {
              this.$message({
                type: "success",
                message: res.msg || res.message,
              });
              this.hideDialog();
              this.$emit("upData");
            } else {
              this.$message({
                type: "error",
                message: res.msg || res.message,
              });
            }
          });
        } else if (this.eduitestablishDialog.dialogType == "smksend") {
          smkcaiwuStatementbank(data).then((res) => {
            if (res.code == 0) {
              this.$message({
                type: "success",
                message: res.msg || res.message,
              });
              this.hideDialog();
              this.$emit("upData");
            } else {
              this.$message({
                type: "error",
                message: res.msg || res.message,
              });
            }
          });
        } else if (this.eduitestablishDialog.dialogType == "smkfaltsend") {
          smkFailChangeBank(data).then((res) => {
            if (res.code == 0) {
              this.$message({
                type: "success",
                message: res.msg || res.message,
              });
              this.hideDialog();
              this.$emit("upData");
            } else {
              this.$message({
                type: "error",
                message: res.msg || res.message,
              });
            }
          });
        }
      },
      //取消
      cancel() {
        this.select = true;
        this.hideDialog();
      },
    },
  };
</script>